package com.ma.cloud.api;

import com.ma.cloud.common.utils.RedisLettuceUtil;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * redis proxy client api
 * @author mr
 * @since 2025-06-23
 */
@Slf4j
@RestController
@RequestMapping("/redis")
@AllArgsConstructor
public class RedisProxyClientApi {


    /**
     * redisLettuceUtil
     */
    private final RedisLettuceUtil redisLettuceUtil;



    @GetMapping("/proxy/direct")
    public Object set(@RequestParam String key) {

        //直连redis客户端
        Object value = redisLettuceUtil.get(key);

        log.info("redis get {} value is : {}", key, value);
        return value;
    }

    @GetMapping("/set")
    public boolean set(@RequestParam String key, @RequestParam String value) {

        boolean result = redisLettuceUtil.set(key, value);
        log.info("redis set key {} value is : {}", key, value);
        return result;
    }

}
